package solicitudesApp.GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.*;

import solicitudesApp.Functions.ControlFiltros;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/

@SuppressWarnings("serial")
public class FormularioFiltros extends javax.swing.JDialog 
{
	private JComboBox jComboBoxFiltro;
	private JLabel jLabelDesde;
	private JButton jButtonCancel;
	private JButton jButtonAplicar;
	private JTextField jTextFieldHasta;
	private JTextField jTextFieldDesde;
	private JLabel jLabelHasta;
	private JLabel jLabelFiltro;
	
	private ControlFiltros func; // feo, necesita interface
	
	public FormularioFiltros(ControlFiltros function) 
	{
		super();
		func = function;
		
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setModalityType(ModalityType.APPLICATION_MODAL);
		setModal(true);
		
		initGUI();
		setLocationRelativeTo(null);
		setVisible(true);
	}
	
	private void initGUI() {
		try {
			{
				this.setTitle("Aplicar filtro");
				getContentPane().setLayout(null);
				this.setLocationByPlatform(true);
				{
					ComboBoxModel jComboBoxFiltroModel = 
						new DefaultComboBoxModel(
								func.getTiposFiltro());
					jComboBoxFiltro = new JComboBox();
					getContentPane().add(jComboBoxFiltro);
					jComboBoxFiltro.setBounds(107, 8, 132, 23);
					jComboBoxFiltro.setModel(jComboBoxFiltroModel);
					jComboBoxFiltro.setSelectedIndex(1);

				}
				{
					jLabelFiltro = new JLabel();
					getContentPane().add(jLabelFiltro);
					jLabelFiltro.setText("Filtro a aplicar:");
					jLabelFiltro.setBounds(12, 11, 89, 16);
					jLabelFiltro.setFont(new java.awt.Font("Segoe UI",1,12));
				}
				{
					jLabelDesde = new JLabel();
					getContentPane().add(jLabelDesde);
					jLabelDesde.setText("Desde");
					jLabelDesde.setBounds(12, 45, 83, 16);
				}
				{
					jLabelHasta = new JLabel();
					getContentPane().add(jLabelHasta);
					jLabelHasta.setText("Hasta");
					jLabelHasta.setBounds(12, 73, 83, 16);
				}
				{
					jTextFieldDesde = new JTextField();
					getContentPane().add(jTextFieldDesde);
					jTextFieldDesde.setBounds(107, 42, 132, 23);
				}
				{
					jTextFieldHasta = new JTextField();
					getContentPane().add(jTextFieldHasta);
					jTextFieldHasta.setBounds(107, 70, 132, 23);
				}
				{
					jButtonAplicar = new JButton();
					getContentPane().add(jButtonAplicar);
					jButtonAplicar.setText("Aplicar");
					jButtonAplicar.setBounds(12, 109, 95, 23);
					jButtonAplicar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButtonAplicarActionPerformed(evt);
						}
					});
				}
				{
					jButtonCancel = new JButton();
					getContentPane().add(jButtonCancel);
					jButtonCancel.setText("Cancelar");
					jButtonCancel.setBounds(144, 109, 95, 23);
					jButtonCancel.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButtonCancelActionPerformed(evt);
						}
					});
				}
			}
			this.setSize(267, 182);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void jButtonAplicarActionPerformed(ActionEvent evt) {
		System.out.println("jButtonAplicar.actionPerformed, event="+evt);
		
		String cual = (String)jComboBoxFiltro.getSelectedItem();
		String desde = jTextFieldDesde.getText();
		String hasta = jTextFieldHasta.getText();
	
		Vector<String> params = new Vector<String>();
		params.add(desde);
		params.add(hasta);
		
		if (func.agregarFiltro(cual, params)) this.dispose();
	}
	
	private void jButtonCancelActionPerformed(ActionEvent evt) {
		System.out.println("jButtonCancel.actionPerformed, event="+evt);
		this.dispose();
	}

}
